package org.admanager.piadl.plugin.diagram.providers;

import org.admanager.piadl.plugin.diagram.edit.parts.ArchitectureNameEditPart;
import org.admanager.piadl.plugin.diagram.edit.parts.ComponentName2EditPart;
import org.admanager.piadl.plugin.diagram.edit.parts.ComponentNameEditPart;
import org.admanager.piadl.plugin.diagram.edit.parts.ConnectorName2EditPart;
import org.admanager.piadl.plugin.diagram.edit.parts.ConnectorNameEditPart;
import org.admanager.piadl.plugin.diagram.parsers.MessageFormatParser;
import org.admanager.piadl.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry;
import org.admanager.piadladmanagement.plugin.piadladmanagement.PiadladmanagementPackage;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
import org.eclipse.gmf.runtime.notation.View;

/**
 * @generated
 */
public class PiADLADManagementMetamodelParserProvider extends AbstractProvider
		implements IParserProvider {

	/**
	 * @generated
	 */
	private IParser connectorName_5010Parser;

	/**
	 * @generated
	 */
	private IParser getConnectorName_5010Parser() {
		if (connectorName_5010Parser == null) {
			EAttribute[] features = new EAttribute[] { PiadladmanagementPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			connectorName_5010Parser = parser;
		}
		return connectorName_5010Parser;
	}

	/**
	 * @generated
	 */
	private IParser componentName_5011Parser;

	/**
	 * @generated
	 */
	private IParser getComponentName_5011Parser() {
		if (componentName_5011Parser == null) {
			EAttribute[] features = new EAttribute[] { PiadladmanagementPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			componentName_5011Parser = parser;
		}
		return componentName_5011Parser;
	}

	/**
	 * @generated
	 */
	private IParser architectureName_5009Parser;

	/**
	 * @generated
	 */
	private IParser getArchitectureName_5009Parser() {
		if (architectureName_5009Parser == null) {
			EAttribute[] features = new EAttribute[] { PiadladmanagementPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			architectureName_5009Parser = parser;
		}
		return architectureName_5009Parser;
	}

	/**
	 * @generated
	 */
	private IParser componentName_5007Parser;

	/**
	 * @generated
	 */
	private IParser getComponentName_5007Parser() {
		if (componentName_5007Parser == null) {
			EAttribute[] features = new EAttribute[] { PiadladmanagementPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			componentName_5007Parser = parser;
		}
		return componentName_5007Parser;
	}

	/**
	 * @generated
	 */
	private IParser connectorName_5008Parser;

	/**
	 * @generated
	 */
	private IParser getConnectorName_5008Parser() {
		if (connectorName_5008Parser == null) {
			EAttribute[] features = new EAttribute[] { PiadladmanagementPackage.eINSTANCE
					.getElement_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			connectorName_5008Parser = parser;
		}
		return connectorName_5008Parser;
	}

	/**
	 * @generated
	 */
	protected IParser getParser(int visualID) {
		switch (visualID) {
		case ConnectorNameEditPart.VISUAL_ID:
			return getConnectorName_5010Parser();
		case ComponentNameEditPart.VISUAL_ID:
			return getComponentName_5011Parser();
		case ArchitectureNameEditPart.VISUAL_ID:
			return getArchitectureName_5009Parser();
		case ComponentName2EditPart.VISUAL_ID:
			return getComponentName_5007Parser();
		case ConnectorName2EditPart.VISUAL_ID:
			return getConnectorName_5008Parser();
		}
		return null;
	}

	/**
	 * Utility method that consults ParserService
	 * @generated
	 */
	public static IParser getParser(IElementType type, EObject object,
			String parserHint) {
		return ParserService.getInstance().getParser(
				new HintAdapter(type, object, parserHint));
	}

	/**
	 * @generated
	 */
	public IParser getParser(IAdaptable hint) {
		String vid = (String) hint.getAdapter(String.class);
		if (vid != null) {
			return getParser(PiADLADManagementMetamodelVisualIDRegistry
					.getVisualID(vid));
		}
		View view = (View) hint.getAdapter(View.class);
		if (view != null) {
			return getParser(PiADLADManagementMetamodelVisualIDRegistry
					.getVisualID(view));
		}
		return null;
	}

	/**
	 * @generated
	 */
	public boolean provides(IOperation operation) {
		if (operation instanceof GetParserOperation) {
			IAdaptable hint = ((GetParserOperation) operation).getHint();
			if (PiADLADManagementMetamodelElementTypes.getElement(hint) == null) {
				return false;
			}
			return getParser(hint) != null;
		}
		return false;
	}

	/**
	 * @generated
	 */
	private static class HintAdapter extends ParserHintAdapter {

		/**
		 * @generated
		 */
		private final IElementType elementType;

		/**
		 * @generated
		 */
		public HintAdapter(IElementType type, EObject object, String parserHint) {
			super(object, parserHint);
			assert type != null;
			elementType = type;
		}

		/**
		 * @generated
		 */
		public Object getAdapter(Class adapter) {
			if (IElementType.class.equals(adapter)) {
				return elementType;
			}
			return super.getAdapter(adapter);
		}
	}

}
